//
//  CCViewController.m
//  诚诚直播
//
//  Created by 张昊 on 16/7/7.
//  Copyright © 2016年 liaoyicheng. All rights reserved.
//

#import "CCViewController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "CCTabbar.h"
#import "CCNavgationController.h"
#import "CameraViewController.h"

@interface CCViewController ()

@end

@implementation CCViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    for (UIView *view in self.tabBar.subviews) {
        if (![view isKindOfClass:[CCTabbar class]]) {
            [view removeFromSuperview];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    CCTabbar *tabBar = [[CCTabbar alloc] init];
    tabBar.frame = self.tabBar.bounds;
//    [self setValue:tabBar forKey:@"tabBar"];
    [self.tabBar addSubview:tabBar];
//    [self.tabBar removeFromSuperview];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectViewController:) name:@"selectViewController" object:nil];
    
    // 添加子控制器
    [self setupChildControllers];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(cameraNotification) name:@"beautifullove" object:nil];
    
    
}

#pragma mark - 选择控制器
- (void)selectViewController:(NSNotification *)noti {
    NSInteger index = [noti.object integerValue];
    
    self.selectedIndex = index - 1;
    
}

- (void)setupChildControllers {
    HomeViewController *home = [[HomeViewController alloc] init];
    [self addChildViewController:[[CCNavgationController alloc] initWithRootViewController:home]];
    
    MineViewController *mine = [[MineViewController alloc] init];
    [self addChildViewController:[[CCNavgationController alloc] initWithRootViewController:mine]];
}

-(void)cameraNotification{

    
    CameraViewController *cameraVC = [UIStoryboard storyboardWithName:NSStringFromClass([CameraViewController class]) bundle:nil].instantiateInitialViewController;
    
    [self presentViewController:cameraVC animated:YES completion:nil];


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
